import gameManager from "./gameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    private gameManager: gameManager = undefined

    init(gameManager: gameManager) {
        this.gameManager = gameManager
    }

    onCollisionEnter(other, self) {
        if (other.node.group == 'abstacle') {
            let n = cc.sys.localStorage.getItem('monster')
            self.node.getComponent(cc.Animation).stop()
            self.node.getComponent(cc.Sprite).SpriteFrame = this.gameManager.failArr[1]
            if (self.node.y > 0) {
                self.node.runAction(cc.sequence(cc.spawn(cc.moveTo(1.5, cc.winSize.width / 2, -cc.winSize.height / 2), cc.rotateTo(1.5, 1080)), cc.callFunc(() => {
                    self.node.destroy()
                    this.gameManager.failGame()
                })))
            } else {
                self.node.runAction(cc.sequence(cc.spawn(cc.moveTo(1.5, cc.winSize.width / 2, cc.winSize.height / 2), cc.rotateTo(1.5, 1080)), cc.callFunc(() => {
                    self.node.destroy()
                    this.gameManager.failGame()
                })))
            }

        } else {
            this.gameManager.addStar()
            other.node.destroy()
        }
    }
}
